package pers.liyan.shi.springboot.task.service;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Service
public class ScheduledService {

    /**
     * cron表达式
     * second as well as minute, hour, day of month, month and day of week
     * 周一到周五整秒执行
     * 0 * * * * MON-FRI
     */
    //每分钟0秒执行
    //@Scheduled(cron = "0 * * * * *")

    //每分钟0,1,2,3,4秒执行(枚举)
    //@Scheduled(cron = "0,1,2,3,4 * * * * *")

    //指定范围(效果同上)
    //@Scheduled(cron = "0-4 * * * * *")

    //指定步长(从第0秒开始每4s执行一次)
    @Scheduled(cron = "0/4 * * * * *")
    /**
     * 使用?进行日/星期冲突匹配
     * 星期匹配中可以使用英文或数字进行匹配 0,7都表示SUN
     */
    public void process(){
        System.out.println("执行定时任务");
        System.out.println(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
    }

}
